package main

import (
	"fmt"
	"net"
)

// 测试协议，看能否在tcp端口识别出http(s)协议以及如何升级，转换协议
func main() {

	lis, err := net.Listen("tcp", ":8080")
	if err != nil {
		panic(err)
	}

	for {
		conn, err := lis.Accept()
		if err != nil {
			panic(err)
		}
		go handleConn(conn)
	}

}

func handleConn(conn net.Conn) {
	for {
		buffer := make([]byte, 1024)

		n, err := conn.Read(buffer)

		if err != nil {
			panic(err)
		}

		body := buffer[:n]

		fmt.Printf("address: 【%s】len:【%d】body: 【%s】\n", conn.RemoteAddr(), n, string(body))
		fmt.Println("----------------")
	}

}
